package day16_Runnable.demo09例子;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;

public class Demo04_Reduce {
    public  void show() throws Exception{
        HashMap<String, Integer> map = new HashMap<>();
        File file = new File("E:\\csw\\Demo\\a");
        File[] files = file.listFiles();
        for (File file1 : files) {
            BufferedReader br = new BufferedReader(new FileReader(file1.getAbsolutePath()));
            String line;
            while ((line=br.readLine())!=null){
                String[] split = line.split(":");
                String clazz = split[0];
                Integer num = Integer.valueOf(split[1]);
                if(map.containsKey(clazz)){
                    map.put(clazz,map.get(clazz)+num);
                }else {
                    map.put(clazz,num);
                }
            }
            br.close();
        }
        System.out.println(map);
    }
}
